/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao.question;

import entities.Proposition;
import entities.question.AbstractQuestion;
import entities.question.QuestionChoix;
import entities.question.QuestionOuverte;
import entities.reponse.ReponseChoix;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author aurelien.emery
 */
@ManagedBean
@SessionScoped
public class TestQuestion {

    @EJB
    private DaoQuestionChoixLocal daoChoix;
    @EJB
    private DaoQuestionOuverteLocal daoOuvert;
    @EJB
    private DaoAbstractQuestionLocal daoQuestion;

    /** Creates a new instance of TestQuestion */
    public TestQuestion() {
    }

    public void tester() {
        testChoix();
        System.out.println("-------------------------------------------------------------------");
        testOuvert();
        System.out.println("-------------------------------------------------------------------");
        testQuestion();
        System.out.println("-------------------------------------------------------------------");
    }

    private void testChoix() {
        System.out.println("test DaoQuestionChoix");
        try {
            int nb = daoChoix.count();
            if (nb <= 0) {
                System.err.println("echec de count : aucun enregistrement");
            } else {
                System.out.println("nb enregistrement : " + nb);
            }
            List<QuestionChoix> qc = daoChoix.findAll();
            if (qc.isEmpty()) {
                System.err.println("echec de findAll : liste vide");
            } else {
                for (QuestionChoix questionChoix : qc) {
                    String temp = new String();
                    for (Proposition prop : questionChoix.getPropositions()) {
                        temp = temp+prop.getTexte()+" / ";
                    }
                    System.out.println(questionChoix.getIntitule()+" : "+temp);
                }
            }
        } catch (Exception ex) {
            System.err.println("echec count daoQuestionChoix : " + ex.getClass().toString());
        }

    }

    private void testOuvert() {
        System.out.println("test DaoQuestionOuvert");
        try {
            int nb = daoOuvert.count();
            if (nb <= 0) {
                System.err.println("echec de count : aucun enregistrement");
            } else {
                System.out.println("nb enregistrement : " + nb);
            }
            List<QuestionOuverte> qc = daoOuvert.findAll();
            if (qc.isEmpty()) {
                System.err.println("echec de findAll : liste vide");
            }

        } catch (Exception ex) {
            System.err.println("echec count daoQuestionOuvert : " + ex.getClass().toString());
        }
    }

    private void testQuestion() {
        System.out.println("test DaoAbstractQuestion");
        try {
            int nb = daoQuestion.count();
            if (nb <= 0) {
                System.err.println("echec de count : aucun enregistrement");
            } else {
                System.out.println("nb enregistrement : " + nb);
            }
            List<AbstractQuestion> qc = daoQuestion.findAll();
            if (qc.isEmpty()) {
                System.err.println("echec de findAll : liste vide");
            } else {
            }

        } catch (Exception ex) {
            System.err.println("echec count daoAbstractQuestion : " + ex.getClass().toString());
        }
    }
}
